home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performPointConstraint.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  12.3 KB  |  497 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  24 April 1997
  22. //
  23. //  Description:
  24. //        This script provides an option box dialog for the pointConstraint command.
  25. //
  26. //    Input Arguments:
  27. //        boolean showOptionBox    true - show the option box dialog
  28. //                                false - just execute the command
  29. //
  30.  
  31. //
  32. //  Procedure Name:
  33. //      setOptionVars
  34. //
  35. //  Description:
  36. //        Initialize the option values.
  37. //
  38. //  Input Arguments:
  39. //        Whether to set the options to default values.
  40. //
  41. //  Return Value:
  42. //      None.
  43. //
  44. proc setOptionVars(int $forceFactorySettings)
  45. {
  46.     //    weight
  47.     //
  48.     if ($forceFactorySettings || !`optionVar -exists pointConstraintWeight`) {
  49.         optionVar -floatValue pointConstraintWeight 1.0;
  50.     }
  51.  
  52.     // offset values
  53.     //
  54.     if ($forceFactorySettings || 
  55.         !`optionVar -exists ptConstOffsetX`) {
  56.         optionVar -floatValue ptConstOffsetX 0.0;
  57.     }
  58.     if ($forceFactorySettings || 
  59.         !`optionVar -exists ptConstOffsetY`) {
  60.         optionVar -floatValue ptConstOffsetY 0.0;
  61.     }
  62.     if ($forceFactorySettings || 
  63.         !`optionVar -exists ptConstOffsetZ`) {
  64.         optionVar -floatValue ptConstOffsetZ 0.0;
  65.     }
  66.  
  67.     // maintain existing offset
  68.     //
  69.     if ($forceFactorySettings || 
  70.         !`optionVar -exists ptConstMaintainOffset`) {
  71.         optionVar -intValue ptConstMaintainOffset 0;
  72.     }
  73.  
  74.     // constraint axes
  75.     //
  76.     if ($forceFactorySettings ||
  77.         !`optionVar -exists  pointConstraintAxisX`) {
  78.         optionVar -intValue pointConstraintAxisX true;
  79.     }
  80.     if ($forceFactorySettings ||
  81.         !`optionVar -exists  pointConstraintAxisY`) {
  82.         optionVar -intValue pointConstraintAxisY true;
  83.     }
  84.     if ($forceFactorySettings ||
  85.         !`optionVar -exists  pointConstraintAxisZ`) {
  86.         optionVar -intValue pointConstraintAxisZ true;
  87.     }
  88.  
  89. }
  90.  
  91. //
  92. //  Procedure Name:
  93. //      pointConstraintSetup
  94. //
  95. //  Description:
  96. //        Update the state of the option box UI to reflect the option values.
  97. //
  98. //  Input Arguments:
  99. //      parent               - Top level parent layout of the option box UI.
  100. //                             Required so that UI object names can be 
  101. //                             successfully resolved.
  102. //
  103. //        forceFactorySettings - Whether the option values should be set to
  104. //                             default values.
  105. //
  106. //  Return Value:
  107. //      None.
  108. //
  109. global proc pointConstraintSetup(string $parent, int $forceFactorySettings)
  110. {
  111.     //    Retrieve the option settings
  112.     //
  113.     setOptionVars($forceFactorySettings);
  114.  
  115.     setParent $parent;
  116.  
  117.     //    Query the optionVar's and set the values into the controls.
  118.  
  119.     //    weight
  120.     //
  121.     floatSliderGrp -edit 
  122.         -value `optionVar -query pointConstraintWeight`
  123.         pointConstraintWeight;
  124.  
  125.     //    Offset values
  126.     //
  127.     float $tx = `optionVar -query ptConstOffsetX`;
  128.     float $ty = `optionVar -query ptConstOffsetY`;
  129.     float $tz = `optionVar -query ptConstOffsetZ`;
  130.     if (`optionVar -query ptConstMaintainOffset`) {
  131.         checkBoxGrp -edit -value1 1 pointConstraintMaintainWidget;
  132.         floatFieldGrp -edit -enable 0 offsetField;
  133.     } else {
  134.         checkBoxGrp -edit -value1 0 pointConstraintMaintainWidget;
  135.         floatFieldGrp -edit -enable 1 offsetField;
  136.     }
  137.     floatFieldGrp -e -v1 $tx -v2 $ty -v3 $tz offsetField;
  138.  
  139.     //  Axis values
  140.     //
  141.     int $axisX = `optionVar -query pointConstraintAxisX`;
  142.     int $axisY = `optionVar -query pointConstraintAxisY`;
  143.     int $axisZ = `optionVar -query pointConstraintAxisZ`;
  144.     // if all axes are on, select the all box and dim the individual axes
  145.     if ($axisX && $axisY && $axisZ) {
  146.         checkBoxGrp -edit -value1 true axesAll;
  147.         checkBoxGrp -edit -value1 false -value2 false -value3 false axesXYZ;
  148.     }
  149.     // otherwise just select those boxes corresponding to 'on' axes
  150.     else {
  151.         checkBoxGrp -edit -value1 false axesAll;
  152.         checkBoxGrp -edit -value1 $axisX -value2 $axisY -value3 $axisZ axesXYZ;     }
  153. }
  154.  
  155. //
  156. //  Procedure Name:
  157. //      pointConstraintCallback
  158. //
  159. //  Description:
  160. //        Update the option values with the current state of the option box UI.
  161. //
  162. //  Input Arguments:
  163. //      parent - Top level parent layout of the option box UI.  Required so
  164. //               that UI object names can be successfully resolved.
  165. //
  166. //        doIt   - Whether the command should execute.
  167. //
  168. //  Return Value:
  169. //      None.
  170. //
  171. global proc pointConstraintCallback(string $parent, int $doIt)
  172. {
  173.     setParent $parent;
  174.  
  175.     //    Set the optionVar's from the control values, and then
  176.     //    perform the command.
  177.  
  178.     //    weight
  179.     //
  180.     optionVar -floatValue pointConstraintWeight
  181.         `floatSliderGrp -query -value pointConstraintWeight`;
  182.  
  183.     // maintain offset
  184.     //
  185.     optionVar -intValue ptConstMaintainOffset `checkBoxGrp  -query -value1 pointConstraintMaintainWidget`;
  186.     
  187.     //    Offset values
  188.     //
  189.     optionVar -floatValue ptConstOffsetX
  190.         `floatFieldGrp -query -v1 offsetField`;
  191.     optionVar -floatValue ptConstOffsetY
  192.         `floatFieldGrp -query -v2 offsetField`;
  193.     optionVar -floatValue ptConstOffsetZ
  194.         `floatFieldGrp -query -v3 offsetField`;
  195.  
  196.     // Axis values
  197.     //
  198.  
  199.     // Either the 'All' box is checked (and so all axes are on) ...
  200.     if ( `checkBoxGrp -query -value1 axesAll` ) {
  201.         optionVar -intValue pointConstraintAxisX true;
  202.         optionVar -intValue pointConstraintAxisY true;
  203.         optionVar -intValue pointConstraintAxisZ true;
  204.     } else {
  205.         // ... Or only those axes specifically selected are on
  206.         optionVar -intValue pointConstraintAxisX
  207.             `checkBoxGrp -query -value1 axesXYZ`;
  208.         optionVar -intValue pointConstraintAxisY
  209.             `checkBoxGrp -query -value2 axesXYZ`;
  210.         optionVar -intValue pointConstraintAxisZ
  211.             `checkBoxGrp -query -value3 axesXYZ`;
  212.     }
  213.  
  214.     if ($doIt) {
  215.         performPointConstraint 0; 
  216.         addToRecentCommandQueue "performPointConstraint 0" "PointConstraint";
  217.     }
  218. }
  219.  
  220. //
  221. //  Procedure Name:
  222. //      pointConstraintOptions
  223. //
  224. //  Description:
  225. //        Construct the option box UI.  Involves accessing the standard option
  226. //        box and customizing the UI accordingly.
  227. //
  228. //  Input Arguments:
  229. //      None.
  230. //
  231. //  Return Value:
  232. //      None.
  233. //
  234. proc pointConstraintOptions()
  235. {
  236.     //    Name of the command for this option box.
  237.     //
  238.     string $commandName = "pointConstraint";
  239.  
  240.     //    Build the option box actions.
  241.     //
  242.     string $callback = ($commandName + "Callback");
  243.     string $setup = ($commandName + "Setup");
  244.  
  245.     //    Get the option box.
  246.     //
  247.     string $layout = getOptionBox();
  248.     setParent $layout;
  249.     
  250.     //    Pass the command name to the option box.
  251.     //
  252.     setOptionBoxCommandName($commandName);
  253.     
  254.     //    Activate the default UI template.
  255.     //
  256.     setUITemplate -pushTemplate DefaultTemplate;
  257.  
  258.     //    Turn on the wait cursor.
  259.     //
  260.     waitCursor -state 1;
  261.  
  262.     tabLayout -scr true -tv false;
  263.     string $parent = `columnLayout -adjustableColumn 1`;
  264.     
  265.     checkBoxGrp
  266.         -label "Maintain Offset"
  267.         -label1 " "
  268.         -annotation "Preserve the initial offset between the object and the target(s)"
  269.         -numberOfCheckBoxes 1
  270.         -cc ("floatFieldGrp -edit -enable (! #1) offsetField;")
  271.         pointConstraintMaintainWidget;
  272.     
  273.     floatFieldGrp -label "Offset"
  274.         -numberOfFields 3
  275.         offsetField;
  276.  
  277.     separator;
  278.     //      Constraint Axes Selection Boxes
  279.     //
  280.  
  281.     // The 'axesAll' checkBoxGrp and the 'axesXYZ' checkBoxGrp are linked
  282.     // such that when 'axesAll' is selected, all the 'axesXYZ' boxes are
  283.     // unselected. And when any 'axesXYZ' box is selected the 'axesAll'
  284.     // box is deselected.
  285.     checkBoxGrp -numberOfCheckBoxes 1 -label "Constraint Axes"
  286.         -label1 "All"
  287.         -onCommand ("checkBoxGrp -edit " +
  288.                     "-value1 false " +
  289.                     "-value2 false " +
  290.                     "-value3 false " +
  291.                     "axesXYZ")
  292.         axesAll;
  293.         
  294.     checkBoxGrp -numberOfCheckBoxes 3
  295.         -label1 "X"
  296.         -label2 "Y"
  297.         -label3 "Z"
  298.         -onCommand ("checkBoxGrp -edit " +
  299.                     "-value1 false " +
  300.                     "axesAll;")
  301.         axesXYZ;
  302.  
  303.     separator;
  304.  
  305.     floatSliderGrp -label "Weight"
  306.         -field true -min 0.0 -max 10.0 
  307.         pointConstraintWeight;
  308.  
  309.     //    Turn off the wait cursor.
  310.     //
  311.     waitCursor -state 0;
  312.     
  313.     //    Deactivate the default UI template.
  314.     //
  315.     setUITemplate -popTemplate;
  316.  
  317.     //    'Apply' button.
  318.     //
  319.     string $applyBtn = getOptionBoxApplyBtn();
  320.     button -edit
  321.         -label "Add"
  322.         -command ($callback + " " + $parent + " " + 1)
  323.         $applyBtn;
  324.  
  325.     //    'Save' button.
  326.     //
  327.     string $saveBtn = getOptionBoxSaveBtn();
  328.     button -edit 
  329.         -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
  330.         $saveBtn;
  331.  
  332.     //    'Reset' button.
  333.     //
  334.     string $resetBtn = getOptionBoxResetBtn();
  335.     button -edit 
  336.         -command ($setup + " " + $parent + " " + 1)
  337.         $resetBtn;
  338.  
  339.     //    Set the option box title.
  340.     //
  341.     setOptionBoxTitle("Point Constraint Options");
  342.  
  343.     //    Customize the 'Help' menu item text.
  344.     //
  345.     setOptionBoxHelpTag( "Point" );
  346.  
  347.     //    Set the current values of the option box.
  348.     //
  349.     eval (($setup + " " + $parent + " " + 0));    
  350.     
  351.     //    Show the option box.
  352.     //
  353.     showOptionBox();
  354. }
  355.  
  356. //
  357. //  Procedure Name:
  358. //      pointConstraintHelp
  359. //
  360. //  Description:
  361. //        Return a short description about this command.
  362. //
  363. //  Input Arguments:
  364. //      None.
  365. //
  366. //  Return Value:
  367. //      string.
  368. //
  369. proc string pointConstraintHelp()
  370. {
  371.     // ******** Example
  372.     // "  Command: Extrude - create a surface using extrusion.\n" +
  373.     // "Selection: curves and isoparms."
  374.  
  375.     return 
  376.     "  Command: pointConstraint - <what it does.>\n" +
  377.     "Selection: <A list of things that can be selected>";    
  378. }
  379.  
  380. //
  381. //  Procedure Name:
  382. //      assembleCmd
  383. //
  384. //  Description:
  385. //        Construct the command that will apply the option box values.
  386. //
  387. //  Input Arguments:
  388. //      None.
  389. //
  390. //  Return Value:
  391. //      None.
  392. //
  393. proc string assembleCmd()
  394. {
  395.     string $cmd = "pointConstraint";
  396.  
  397.     setOptionVars(false);
  398.  
  399.     if (`optionVar -query ptConstMaintainOffset`) {
  400.         $cmd = ($cmd + " -mo");
  401.     } else {
  402.         //    Translate values
  403.         //
  404.         float $tx = `optionVar -query ptConstOffsetX`;
  405.         float $ty = `optionVar -query ptConstOffsetY`;
  406.         float $tz = `optionVar -query ptConstOffsetZ`;
  407.         $cmd = ($cmd + " -offset " + $tx + " " + $ty + " " + $tz );
  408.     }
  409.     
  410.     // Axis values
  411.     //
  412.  
  413.     // The axis values are inverted so that they represent
  414.     // which axes to *skip* as opposed to which axes are on.
  415.     int $axisX = !`optionVar -query pointConstraintAxisX`;
  416.     int $axisY = !`optionVar -query pointConstraintAxisY`;
  417.     int $axisZ = !`optionVar -query pointConstraintAxisZ`;
  418.  
  419.     // If any of these values is true, that means that one
  420.     // or more axes are to be skipped.
  421.     if ($axisX)
  422.         $cmd = ($cmd + " -skip x");
  423.     if ($axisY)
  424.         $cmd = ($cmd + " -skip y");
  425.     if ($axisZ)
  426.         $cmd = ($cmd + " -skip z");
  427.  
  428.     $cmd = ($cmd +
  429.             " -weight " + `optionVar -query pointConstraintWeight`);
  430.         
  431.     return $cmd;
  432. }
  433.  
  434. //
  435. //  Procedure Name:
  436. //      performPointConstraint
  437. //
  438. //  Description:
  439. //        Perform the pointConstraint command using the corresponding 
  440. //        option values.  This procedure will also show the option box
  441. //        window if necessary as well as construct the command string
  442. //        that will invoke the pointConstraint command with the current
  443. //        option box values.
  444. //
  445. //  Input Arguments:
  446. //      0 - Execute the command.
  447. //      1 - Show the option box dialog.
  448. //      2 - Return the command.
  449. //
  450. //  Return Value:
  451. //      None.
  452. //
  453. global proc string performPointConstraint(int $action)
  454. {
  455.     string $cmd = "";
  456.  
  457.     switch ($action) {
  458.  
  459.         //    Execute the command.
  460.         //
  461.         case 0:
  462.             //    Retrieve the option settings
  463.             //
  464.             setOptionVars(false);
  465.  
  466.             //    Get the command.
  467.             //
  468.             $cmd = `assembleCmd`;
  469.  
  470.             //    Execute the command with the option settings.
  471.             //
  472.             evalEcho($cmd);
  473.  
  474.             break;
  475.  
  476.         //    Show the option box.
  477.         //
  478.         case 1:
  479.             pointConstraintOptions;
  480.             break;
  481.  
  482.         //    Return the command string.
  483.         //
  484.         case 2:
  485.             //    Retrieve the option settings.
  486.             //
  487.             setOptionVars (false);
  488.  
  489.             //    Get the command.
  490.             //
  491.             $cmd = `assembleCmd`;
  492.             break;
  493.     }
  494.     return $cmd;
  495. }
  496.  
  497.